﻿using NDK.Motion.BLL;
using System;
using System.ComponentModel;
using static NDK.Module.Model.Common;

namespace NDK.Module.StationLogic
{
    public class CheckVacuum : StationLogicBase
    {
        public override event PropertyChangedEventHandler PropertyChanged;

        public static CheckVacuum Instance = new CheckVacuum();
        //私有化的构造函数
        private CheckVacuum() : base()
        {
            this.Name = "检测真空站";
        }

        /// <summary>
        /// 工站初始化
        /// </summary>
        public override void Init()
        {
            base.Init();
            foreach (var item in Machine.DicCheckVacuum.Keys)
            {
                Machine.DicCheckVacuum[item].CheckStationVacuumbool = false;
            }
        }

        public override void ActionProcess()
        {
            if (!屏蔽真空检测)
            {
                foreach (var item in Machine.DicCheckVacuum.Keys)
                {
                    if (Machine.DicCheckVacuum[item].CheckStationVacuumbool)
                    {
                        if (!Machine.DicInputIO[item].GetStatus())
                        {
                            if ((DateTime.Now - Machine.DicCheckVacuum[item].CheckVacuumTime).TotalMilliseconds > 掉料报警延时)
                            {
                                AlarmPause("吸真空报警", $"{item}，请检查", "存在掉料现象，请检查", "重新检测", "忽略报警，继续运行");
                                Machine.DicCheckVacuum[item].CheckVacuumTime = DateTime.Now;
                            }
                        }
                    }
                    else
                        Machine.DicCheckVacuum[item].CheckVacuumTime = DateTime.Now;
                }
            }
        }

        public override void EmptyActionProcess()
        {
            ActionProcess();
        }

        public override void GRRActionProcess()
        {
            ActionProcess();
        }
    }
}
